package ch.fusun.baron.player;

import java.util.LinkedList;
import java.util.List;

import ch.fusun.baron.coatofarms.ui.CoatOfArmsData;

/**
 * A user plays a dynasty. It represents a family of players which can be
 * controlled by that user
 */
public class Dynasty {
	private List<Player> persons = new LinkedList<Player>();
	private String name;
	private CoatOfArmsData coa;

	/**
	 * Kryo
	 */
	public Dynasty() {
	}

	/**
	 * @param name
	 *            The name of the dynasty
	 * @param coa
	 *            The coat of arms
	 */
	public Dynasty(String name, CoatOfArmsData coa) {
		this.name = name;
		this.coa = coa;
	}

	@Override
	public boolean equals(Object arg0) {
		if (arg0 instanceof Dynasty) {
			return this.name.equals(((Dynasty) arg0).name);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}

	/**
	 * @return The members of this {@link Dynasty}
	 */
	public List<Player> getMembers() {
		return persons;
	}

	/**
	 * @param persons
	 *            The members of this {@link Dynasty}
	 */
	public void setPersons(List<Player> persons) {
		this.persons = persons;
	}

	/**
	 * @param player
	 *            Adds the player to dynasty
	 */
	public void addPlayer(Player player) {
		this.persons.add(player);
	}

	@Override
	public String toString() {
		return name;
	}

	/**
	 * @return The coat of arms of the {@link Dynasty}
	 */
	public CoatOfArmsData getCoatOfArms() {
		return coa;
	}

	/**
	 * @return The name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Updates the person if available
	 * 
	 * @param person
	 */
	public void updatePerson(Player person) {
		int indexOf = persons.indexOf(person);
		if (indexOf != -1) {
			persons.set(indexOf, person);
		}
	}

	/**
	 * @param player
	 *            Person to be removed from {@link Dynasty}
	 */
	public void removePerson(Player player) {
		this.persons.remove(player);
	}
}
